$(function(){
	$(".mc").css("display","none");
	$('#categorys').hover(function(){
		$(this).children('.mc').toggle();
	});
	$Base.isLogin(location.href, getOrderList);
	$('#order_date').bind('change',getOrderList);
	$('#status').bind('change',getOrderList);
});

function queryByName(){
	var name = $.trim($('#product_name').val());
	if(name == '商品名称' || name.length == 0){
		$('#product_name').val('')
	}
	getOrderList();
}

function getOrderList() {
	var url = '/json?action=QUERY_T_ORDER_BY_PAGER_ACTION';
	url += '&DATE=' + $('#order_date').val();
	url += '&STATUS=' + $('#status').val();
	var name = $.trim($('#product_name').val());
	if(name != '商品名称'){
		url += '&PRODUCT_NAME=' + name ;
	}
	var pageSize = 10;
	var defaultHtml = '<tr><td colspan="7" align="center" height="230px">没有查询到相关的订单信息</td></tr>';
	var current = $Util.getQueryString(document.location.search,'current');
	$UI.changePage(url,pageSize,'T_ORDER','#order_list',printOrder,'#pager',defaultHtml,current,'#topPagePanel');
}

function printOrder(obj,result,i,n,len,c,t) {
	if (t) {
		$('#totalProducts').html('共<strong>'+t+'</strong>个订单');
		$('#pageShow').html(c+'/'+(Math.floor(t/10)+1));
	}
	
	var productList = JSON.parse(obj.PRODUCT);
	var div = "";
	div +=	'<tbody class="success-order">';
	div +=		'<tr class="sep-row"><td colspan="7"></td></tr>';
	div +=		'<tr class="order-hd">';
	div +=			'<td colspan="7">';
	div +=				'<span class="no"><label>&nbsp;&nbsp;订单编号：<span class="order-num">'+obj.ORDER_ID+'</span></label></span>';
	div +=				'<span class="deal-time">成交时间：'+$Util.toChar(obj.ORDER_DATE, 'yyyy-mm-dd hh24:mi:ss')+'</span>';
	div +=			'</td>';
	div +=		'</tr>';
			$.each(productList, function(j, o){
	div +=		'<tr class="order-bd">';
	div +=			'<td class="baobei" colspan="2">';
	div +=				'<a href="../product/file.html?id='+o.PRODUCT_ID+'" class="pic s50" target="blank"><img src="../upload/product/'+o.PRODUCT_NO+'.jpg" /></a>';
	div +=				'<span class="desc">';
	div +=					'<a href="../product/file.html?id='+o.PRODUCT_ID+'" target="blank">'+o.PRODUCT_NAME+'</a>';
//	div +=					'<div class="spec"><span>尺码: S</span></div>'+
	div +=				'</span>';
	div +=			'</td>';
	div +=			'<td class="price">￥'+(o.MEMBER_PRICE).toFixed(2)+'</td>';
	div +=			'<td class="quantity">'+o.QTY+'</td>';
				if(j == 0){	
	div +=			'<td class="amount" rowspan="'+productList.length+'"><strong>￥'+(obj.PAYMENT).toFixed(2)+'</strong></td>';
	div +=			'<td class="trade-status" rowspan="'+productList.length+'">';
					var className = 'red';
					if(obj.STATUS == 7){
						className = 'green';
					} else if(obj.STATUS == 8){
						className = 'cGray';
					}
	div +=				'<a href="order_detail.html?id='+obj.ORDER_ID+'" class="'+ className +'" target="_blank">'+$Base.getOrderStatus(obj.STATUS)+'</a>';
	div +=				'<span><a href="order_detail.html?id='+obj.ORDER_ID+'" target="_blank">订单详情</a></span>';
	div +=				'<span class="cGray">'+ (obj.IS_COMMENT == 1 ? "已评价" : "") +'</span>';
	div +=			'</td>';
	div +=			'<td class="operate" rowspan="'+productList.length+'">'+ (obj.STATUS == 7 ? (obj.IS_COMMENT == 0 ? "<a href=\"evaluate.html?id="+obj.ORDER_ID+"\">评价</a>" : "&nbsp;") : '&nbsp;') + '</td>';
//	div +=			'<td class="other" rowspan="'+productList.length+'">';
//	div +=				'<a href="javascript:void(0)" class="blue">删除</a>';
//	div +=				'<a href="#" class="blue">备忘</a>';
//	div +=				'<a href="#" class="blue">分享</a>';
//	div +=			'</td>';
				}
	div +=		'</tr>';
			});
	div +=	'</tbody>'
	$(result).append(div);
	if(i == len - 1){
		var html = $(result).html();
		$('tbody.success-order').remove();
		$(result).after(html);
	}
}